﻿using FreeSql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CKS.Schedule
{
    public partial class CronJobBase
    {
        // 获取源表的所有字段名（通过数据库元数据）
        public List<string> GetSourceTableColumns(IFreeSql fsql, string tableName)
        {
            return fsql.Ado.DataType switch
            {
                DataType.MySql => fsql.Ado.Query<string>(@"
                SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 
                WHERE TABLE_NAME = @TableName", new { TableName = tableName }).ToList(),
                DataType.SqlServer => fsql.Ado.Query<string>(@"
                SELECT name FROM sys.columns 
                WHERE object_id = OBJECT_ID(@TableName)", new { TableName = tableName }).ToList(),
                _ => throw new NotSupportedException("不支持的数据库类型")
            };
        }

    }
}
